<?php
class ReportsController extends AppController {

  	
    var $name = 'Reports';
    var $uses = array('Desposit','Vehicle','Master');
    var $helpers = array('Ajax','Time');        
    var $components = array('RequestHandler');
    
       function index(){
                $this->set('title_for_layout', 'Reportes');
                $this->pageTitle = 'Busquedas';
                $desposits = $this->Desposit->find('list',array('fields'=>'descripcion'));
                $this->log($desposits);
                $this->set(compact('desposits'));
       }
       function report(){  
           $this->set('title_for_layout', 'Reportes');
               $this->loadModel('VehiclesTypes');
               $cant =  count($this->data['Reports']['desposits']);
               for($h=0;$h<=$cant;$h++){ 
               if(!empty($this->data['Reports']['desposits'][$h])){
                   $this->loadModel('State');
                   $cant_states = $this->State->find('count');
                   $cant_vehicles_types = $this->VehiclesTypes->find('count');
                   $desc_states = $this->State->find('list',array('fields'=>'descripcion'));
                   
                   $cant_vehiculos[$h] = $this->Master->find('count',array(
                                                              'conditions'=>array(
                                                                            'Master.desposits_id '=>$this->data['Reports']['desposits'][$h]
                                                                            ),
                                                                        )
                                                         ); 
                   for($i=1;$i<=$cant_states;$i++){
                       for($j=1;$j<=$cant_vehicles_types;$j++){
                         $estado_vehiculos[$h][$i][$j] = $this->Master->find('count',array(
                                                              'conditions'=>array(
                                                                            'Master.desposits_id ' => $this->data['Reports']['desposits'][$h],
                                                                            'Master.states_id' => $i,
                                                                            'Vehicles.vehicles_types_id' => $j
                                                                            ),
                                                                   )
                                                            );
                            }
                          $cant_estados[$h][$i] = $this->Master->find('count',array(
                                                              'conditions'=>array(
                                                                            'Master.desposits_id ' => $this->data['Reports']['desposits'][$h],
                                                                            'Master.states_id' => $i,
                                                                            ),
                                                                   )
                                                            );
                   }
                    $desposits[$h] = $this->Desposit->findById($this->data['Reports']['desposits'][$h]);
               }//
               
       }           
               $vehicles_types = $this->VehiclesTypes->find('list',array('fields'=>'descripcion'));
               
               $this->set(compact('desposits','vehicles_types','estado_vehiculos','cant_vehiculos',
                                  'desc_states','cant_vehicles_types','cant_states','cant_estados','cant'));
       }
}
?>
